package com.macro.mall.controller;

import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.UmsMemberReceiveAddress;
import com.macro.mall.service.UmsMemberReceiveAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author：MinxiaoHao
 * @Description:
 * @name：UmsMemberReceiveAddressController
 * @Date：2024/10/22 21:40
 */
@RestController
@RequestMapping("/member/address")
public class UmsMemberReceiveAddressController {
    @Autowired
    private UmsMemberReceiveAddressService memberReceiveAddressService;

    /**
     * 获取收货地址列表
     * @return
     */
    @GetMapping("/list")
    public CommonResult<List<UmsMemberReceiveAddress>> list(){
        List<UmsMemberReceiveAddress> list = memberReceiveAddressService.selectList();
        return CommonResult.success(list);
    }

    /**
     * 添加收货地址
     * @param address 地址详情
     */
    @PostMapping("/add")
    public CommonResult add(@RequestBody UmsMemberReceiveAddress address){
        return CommonResult.success(memberReceiveAddressService.save(address));
    }

    /**
     * 修改收货地址
     * @param address 地址详情
     */
    @PostMapping("/update/{id}")
    public CommonResult update(@RequestBody UmsMemberReceiveAddress address){
        return CommonResult.success(memberReceiveAddressService.updateById(address));
    }

    /**
     * 删除收货地址
     * @param id 收货地址id
     */
    @PostMapping("/delete/{id}")
    public CommonResult delete(@PathVariable Long id){
        return CommonResult.success(memberReceiveAddressService.removeById(id));
    }

    /**
     * 根据id查询收货地址
     * @param id 收货地址id
     */
    @GetMapping("/{id}")
    public CommonResult<UmsMemberReceiveAddress> getItem(@PathVariable Long id){
        return CommonResult.success(memberReceiveAddressService.getById(id));
    }
    /**
     * 快递识别
     * @param addressInfo 快递信息
     */
    @GetMapping("/identification/{addressInfo}")
    public CommonResult identification(@PathVariable String addressInfo){
        UmsMemberReceiveAddress umsMemberReceiveAddress=memberReceiveAddressService.identification(addressInfo);
        return CommonResult.success(umsMemberReceiveAddress);
    }
}
